package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 模板类型枚举
 * 
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum TemplateType implements BaseEnum {
    EXAM("exam", "考试模板"),
    QUIZ("quiz", "测验模板"),
    ASSIGNMENT("assignment", "作业模板"),
    PRACTICE("practice", "练习模板"),
    FINAL("final", "期末考试模板"),
    MIDTERM("midterm", "期中考试模板"),
    MAKEUP("makeup", "补考模板"),
    SPECIAL("special", "特殊考试模板"),
    ONLINE("online", "在线考试模板"),
    OFFLINE("offline", "线下考试模板"),
    MIXED("mixed", "混合模式模板"),
    STANDARD("standard", "标准模板"),
    CUSTOM("custom", "自定义模板"),
    SYSTEM("system", "系统模板");

    private final String code;
    private final String description;

    TemplateType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static TemplateType fromCode(String code) {
        for (TemplateType type : TemplateType.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown template type code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static TemplateType fromDescription(String description) {
        for (TemplateType type : TemplateType.values()) {
            if (type.description.equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown template type description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}